-
Notifications
You must be signed in to change notification settings - Fork 513
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[rtl872x] hal: fix issue that uart rx dma may hang up. #2502
Conversation
services/inc/ringbuffer.h
Outdated
@@ -310,7 +310,7 @@ inline ssize_t RingBuffer<T>::acquireCommit(size_t size, size_t cancel) { | |||
|
|||
headPending_ -= (size + cancel); | |||
head_ = wrap(head_ + size, curSize_); | |||
full_ = ((head_ == tail_) && size > 0); | |||
full_ = ((head_ == tail_) && size > 0) || full_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: let's change this for readability:
if (size > 0) {
full_ = (head_ == tail_);
}
We should only be updating full_
flag if we are modifying head_
.
flushDmaRxFiFo(transferredToDmaFromUart); | ||
} else { | ||
toConsume = dmaAvailableInBuffer - alreadyCommitted; | ||
// Try not suspending DMA unless necessary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
hal/src/rtl872x/usart_hal.cpp
Outdated
if (hal_interrupt_is_isr()) { | ||
// This method is called from DMA RX ISR | ||
// Clear UART RX FIFO read counter ASAP, because UART might be still receiving data | ||
uartInstance->RX_BYTE_CNT |= RUART_RX_BYTE_CNTER_CLEAR; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be necessary to perform here. DMA will not be reading data out of UART FIFO if the transaction just finished. The counter will stay the same. This is not data put into UART FIFO, this is data transmitted from UART FIFO into DMA FIFO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is possible that other interrupts with higher priority may interrupt the executtion of the UART RX DMA ISR, while the UART is receiving data. If we clear the counter later in the DMA ISR, we might lose some bytes, especially with higher baudrate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We won't. We are resetting RX_BYTE_CNT only at the end of the DMA transaction. Once DMA transaction finishes RX_BYTE_CNT will no longer increase because DMA no longer transfers data out of UART FIFO into its internal FIFO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see 👍 . Accordding to the REG_RX_BYTE_CNT
's description:
Counting the byte number of data reading from Rx FIFO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's an actual number of bytes already transferred from UART FIFO into DMA FIFO, so already in DMA FIFO.
cdd2cd2
to
8a552ca
Compare
Problem
When running the Serial2 stress test app as attached below, device may hang up over time.
Solution
Steps to Test
Build and run the below test app.
Example App
References
N/A
Completeness